using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Publicuse.Entity;
using Publicuse.Util;

namespace Publicuse.Export
{
  /// <summary>
  /// 黑白名单管理信息导出辅助类
  /// </summary>
  public class WhitesinglenameExport
  {
    /// <summary>
    /// 黑白名单管理导出数据设置
    /// </summary>
    /// <param name="excelName"></param>
    /// <param name="fileName"></param>
    /// <param name="list"></param>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static MemoryStream ExportData(
      string fileName,
      string excelName,
      List<Whitesinglename> list,
      out string msg
    )
    {
      msg = string.Empty;
      MemoryStream ms = ExcelUtil.GetExcelUtil.InitExportData(
        fileName,
        excelName,
        list,
        (row, cell, sheet1, TextSytle, srow, hssfworkbook) =>
        {
          foreach (Whitesinglename item in list)
          {
            srow++;
            row = sheet1.CreateRow(srow);
            //IP地址
            cell = row.CreateCell(0);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.IPAddress);
            //IP编码
            cell = row.CreateCell(1);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.IPCode);
            //类型 1=白名单 2=黑名单
            cell = row.CreateCell(2);
            cell.CellStyle = TextSytle;
            var newvalue = item.type == 1 ? "白名单" : "黑名单";
            cell.SetCellValue(newvalue);
            //状态
            cell = row.CreateCell(3);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.status == 1 ? "正常" : "停用");
            //创建时间
            cell = row.CreateCell(4);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.cTime.ToString("yyyy-MM-dd HH:mm:ss"));
            //更新时间
            cell = row.CreateCell(5);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.uTime?.ToString("yyyy-MM-dd HH:mm:ss"));
            //描述
            cell = row.CreateCell(6);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.Remark);
          }
        },
        out msg,
        2
      );
      return ms;
    }
  }
}
